<?php
/**
 * 班级信息的添加、修改和删除
 */
include "../util/DBUtil.php";

$action = $_GET['flag'];//获取操作行为
$id = $_GET['id'];
$db = new DBUtil();
$sql = "";
$params = array();

if ($action==0){//修改操作
    $sql = "select * from tb_grade where id=?";
    $params = array($id);
    $result = $db->query($sql,$params)[0];//存储结果
}elseif($action==1){//删除操作
    $sql = "delete from tb_grade where id=?";
    $params = array($id);
    $f = $db->delete($sql,$params);
    if ($f!=1){//删除失败
        echo "<script>alert('不可删除，请先删除该班学生信息！');</script>";
    }else{
        echo "<script>alert('删除成功');</script>";
    }
    echo "<script>window.open('grade.php','info')</script>";
    return;
}
?>

<form action="../action/grade_formOK.php" method="post">
    <input type="hidden" name="id" value="<?php echo $id?>">
    班级：<input type="text" name="grade" value="<?php echo $action==0? $result['grade']:'' ?>">
    <button type="submit" formtarget="info">确定</button>
</form>
